﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Zhaoxi.MvvmLightLesson.ViewModels
{
    internal class MainViewModel : ObservableObject
    {
        private int _value;

        public int Value
        {
            get { return _value; }
            set
            {
                //_value = value;
                //PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Value"));
                //this.RaisePropertyChanged("Value");

                Set(ref _value, value);
            }
        }

        // 不带参数
        public RelayCommand ButtonCommand { get; set; }
        // 带参数命令
        public RelayCommand<string> ButtonStringCommand { get; set; }

        public MainViewModel()
        {
            ButtonCommand = new RelayCommand(DoButtonCommand);
            ButtonStringCommand = new RelayCommand<string>(DoButtonStringCommand);
        }
        private void DoButtonCommand()
        {
            // 
        }

        private void DoButtonStringCommand(string value)
        {
            // View引用了VIewModel    
            // ViewModel不能引用View    循环引用
            // 常见场景：弹窗
            Messenger.Default.Send<string>(value, "AAAA");
        }

        // 代码片段



    }
}
